package cn.tedu.ivos.user.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.user.pojo.dto.UserLoginParam;
import cn.tedu.ivos.user.pojo.dto.UserQuery;
import cn.tedu.ivos.user.pojo.dto.UserSaveParam;
import cn.tedu.ivos.user.pojo.vo.UserVO;
import cn.tedu.ivos.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 482944566@qq.com
 * @version 1.0
 * @date 2024-11-29
 */
@Api(tags = "用户模块")
@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation("用户登录")
    @PostMapping("login")
    public JsonResult login(UserLoginParam userLoginParam){
       log.debug("用户登录userLoginParam={}",userLoginParam);
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }

    @ApiOperation("新增用户")
    @PostMapping("save")
    public JsonResult save(UserSaveParam userSaveParam){
        log.debug("userSaveParam={}",userSaveParam);
        userService.saveUser(userSaveParam);
        return JsonResult.ok();
    }

    @ApiOperation("查询用户")
    @GetMapping("select")
    public JsonResult select(UserQuery userQuery){
        log.debug("userQuery={}",userQuery);
        List<UserVO> list =  userService.selectUser(userQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation("密码重置")
    @PostMapping("/update/password/{userId}")
    public JsonResult resetPassword(@PathVariable Long userId){
        log.debug("密码重置，userId={}",userId);
        userService.resetPassword(userId);
        return JsonResult.ok();
    }

    @PostMapping("/update/status/{userId}/{status}")
    public JsonResult updateStatus(@PathVariable Long userId,@PathVariable String status){
        log.debug("修改用户状态，userId={},status={}",userId,status);
        userService.updateStatus(userId,status);
        return JsonResult.ok();
    }

    @PostMapping("/deleteUser/{userId}")
    public JsonResult deleteUser(@PathVariable Long userId){
        log.debug("删除用户,userId={}",userId);
        userService.deleteUser(userId);
        return JsonResult.ok();
    }

    @GetMapping("/select/audit/{parentId}")
    public JsonResult selectAuditList(@PathVariable Long parentId){
        log.debug("查询审批人列表：parentId={}",parentId);
        List<UserVO> list = userService.selectAuditList(parentId);
        return JsonResult.ok(list);
    }
}
